package com.wyh.recketmq.seckill.service;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Service;


/**
 * @author wuyuhan
 * @date 2021/5/15 22:23
 */
@Service
@RocketMQMessageListener(topic = "rocket-orderDelay", consumerGroup = "orderDelay")
public class ConsumerDelayService implements RocketMQListener<MessageExt>, RocketMQPushConsumerLifecycleListener {
    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            String orderStr = new String(messageExt.getBody(), "utf-8");
            //持久化到数据库
            System.out.println(orderStr);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {

    }
}
